package myDuoXianChen;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/10/19-上午11:14
 * Since  :   1.0
 * Version:   1.0
 */
public class JoinExample {
    public static void main(String[] args) {
        MyThread thread = new MyThread();
        thread.start(); // 启动线程

        try {
            System.out.println("主线程开始");
            thread.join(); // 等待 thread 执行完毕
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("主线程继续执行");
    }
}

class MyThread extends Thread {
    public void run() {
        System.out.println("线程正在执行...");
        try {
            Thread.sleep(2000); // 模拟耗时操作
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程执行完毕");
    }
}